<?php
namespace Suo\Model;
use Think\Model;

class CookBookModel extends Model {
	private $_db='';
	public function __construct(){
		$this->_db=M('cookbook');
	}
	
	public function getCookList($data,$page,$pageSize=10){
		$conditions = $data;
		if(isset($data['dish_name']) && $data['dish_name']){
			$conditions['dish_name'] = array ('like','%'.$data['dish_name'].'%');
		}
		
		$offset = ($page - 1) * $pageSize;
		$list = $this->_db->where($conditions)
		->order('id desc')
		->limit($offset,$pageSize)
		->select();
		return $list;
	}
	
	public function getCookBookById ($id){
		if(!is_numeric($id) || !$id){
			throw_exception("ID不合法");
		}
		$cook = $this->_db->where('id='.$id)->find();
		return $cook;
	}
}
